function V = valfunc(Ap,s,coeffs,t,param,glob)

    % Compute flow payoff
    % if the agent is retired:
    if t>=glob.R
        cons = menufun('consumption',Ap,s,t,param,glob);
        flow = param.beta.*log(cons-glob.gammac) ...
            + (1-param.beta).*log(glob.gammah);
    
    % if the agent if working:    
    else
        % compute consumption and hours
        cons = menufun('consumption',Ap,s,t,param,glob);
        hrs  = menufun('hours',Ap,s,t,param,glob);
        
        % plug into utility function
        flow = param.beta.*log(cons-glob.gammac) +...
            (1-param.beta).*log(glob.gammah-hrs);
    end

    % Compute continuation value (known)
    cont = funbas(glob.fspace,Ap)*coeffs;
    
    % Finally, compute RHS of value function at specified A'
    V = flow + 1./(1+param.delta)*cont;
    
end